package com.financing.platform.dao.impl;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.financing.platform.dao.IActionDao;
import com.financing.platform.dao.IJpushMessageDao;
import com.financing.platform.dto.ActionDTO;
import com.financing.platform.dto.MessageJpushDTO;
import com.financing.platform.dto.MessageJpushUserPhoneAliasDTO;
import com.financing.platform.util.SqlName;

@Repository("jpushMessageDao")
public class JpushMessageDaoImpl extends BaseDaoImpl implements IJpushMessageDao {

	@Override
	public List<MessageJpushDTO> queryJpushMessageList(MessageJpushDTO dto) throws SQLException {
		return this.sqlMapClient.queryForList(SqlName.queryMessageJpush,dto);
	}

	@Override
	public int addJpushMessage(MessageJpushDTO dto) throws SQLException {
		if(StringUtils.isBlank(dto.getFpJpushMsgRec())  && !"02".equals(dto.getFpJpushMsgType()) && !"06".equals(dto.getFpJpushMsgType())) {
			return 0;
		}
		return (Integer) this.sqlMapClient.insert(SqlName.addMessageJpush, dto);
	}

	@Override
	public int updateJpushMessage(MessageJpushDTO dto) throws SQLException {
		return this.sqlMapClient.update(SqlName.updateMessageJpush, dto);
	}

	@Override
	public List<MessageJpushDTO> queryJpushMessageListForJob(MessageJpushDTO dto)  {
		try {
			return this.sqlMapClient.queryForList(SqlName.queryMessageJpushForJob,dto);
		} catch (SQLException e) {
			log.error("query jpush messageList for job error!" ,e);
			return Collections.EMPTY_LIST;
		}
	}

	@Override
	public int queryMessageJpushCount(MessageJpushDTO dto) throws SQLException {
		return (Integer) this.sqlMapClient.queryForObject(SqlName.queryMessageJpushCount, dto);
	}

	@Override
	public List<MessageJpushUserPhoneAliasDTO> queryJpushUserPhonealias(String faId) throws SQLException {
		return this.sqlMapClient.queryForList(SqlName.queryJpushUserPhonealias, faId);
	}


}
